import Vue from "vue";
import VueRouter from 'vue-router'
import Login from '../pages/Login.vue'
import Main from '../pages/Main.vue'

Vue.use(VueRouter)

const routes=[
    {   path:'/',
        //重定向/loin(path)
        component:Main,
        redirect:'/user/room',
        name:'Main',
    },
    
    {   path:'/user',
        name:'User',
        component:Main,
        children:[
            {path:'user',name:'UserUser',component:() =>import('@/pages/user/user/List')},
            {path:'room',name:'UserRoom',component:() =>import('@/pages/user/room/List.vue')},
            {path:'book',name:'UserBook',component:() =>import('@/pages/user/book/List.vue')},
            {path:'bill',name:'UserBill',component:() =>import('@/pages/user/bill/List.vue')},

        ]

    },
    {   path:'/admin',
        name:'Admin',
        component:Main,
        children:[
            {path:'room',name:'AdminRoom',component:() =>import('@/pages/admin/room/List.vue'),},
            {path:'user',name:'AdminUser',component:() =>import('@/pages/admin/customer/List.vue'),},
            {path:'book',name:'AdminBook',component:() =>import('@/pages/admin/book/List.vue'),},
            {path:'bill',name:'AdminBill',component:() =>import('@/pages/admin/bill/List.vue'),},
            {path:'employee',name:'AdminEmp',component:() =>import('@/pages/admin/employee/List.vue'),},
        ]

    },
    {path:'/addroom',name:'Addroom',component:() =>import('@/pages/admin/room/Add.vue'),},
    {path:'/addemp',name:'AddEmp',component:() =>import('@/pages/admin/employee/Add.vue'),},
    {path:'/login',name:'Login',component:Login},
     
]
const router = new VueRouter({
    mode: 'history',
    
    routes,
})
/* router.beforeEach((to,from,next)=>{
    if(to.matched.some(record => record.meta.requireAuth)){
        const token = localStorage.getItem("uToken")
        if(token){
            // if(to.path ==="/login"){

            // }else{
            //     next()
            // }
        }else{
            ElementUI.Message({
                message:'请先登录',
                type:'warning'
            })
            next({name:'Login'})
        }
    }else{
        next()
    }
}) */

export default router
